# Maintainer: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
pkgname=xtensa-dynconfig
pkgver=0_git20231013
_commit_xtensa_dynconfig=905b913aa65638be53ac22029c379fa16dab31db
_commit_xtensa_overlays=dd1cf19f6eb327a9db51043439974a6de13f5c7f
pkgrel=0
pkgdesc="GCC/binutils/GDB plugin to configure xtensa CPU specification"
url="https://github.com/espressif/xtensa-dynconfig"
# limited by binutils-xtensa-none-elf, gcc-xtensa-none-elf, g++-xtensa-none-elf
arch="aarch64 x86_64"
# xtensa-dynconfig: GPL-3.0-only
# xtensa-overlays: Not stated, but GPL-2.0-or-later and MIT in the headers
license="GPL-3.0-only AND GPL-2.0-or-later AND MIT"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/espressif/xtensa-dynconfig/archive/$_commit_xtensa_dynconfig.tar.gz
	$pkgname-overlays-$_commit_xtensa_overlays.tar.gz::https://github.com/espressif/xtensa-overlays/archive/$_commit_xtensa_overlays.tar.gz
	"
builddir="$srcdir/$pkgname-$_commit_xtensa_dynconfig"
options="!check" # no unit tests provided

_targets="
	esp32
	esp32s2
	esp32s3
	esp8266
	"

for target in $_targets; do
	subpackages="
		xtensa-dynconfig-$target:_lib
		$subpackages
		"
done

prepare() {
	ln -s "$srcdir/xtensa-overlays-$_commit_xtensa_overlays" "$builddir/config"

	default_prepare
}

build() {
	make
}

package() {
	mkdir -p "$pkgdir"
}

_lib() {
	local target
	target="${subpkgname#xtensa-dynconfig-}"
	pkgdesc="Tools necessary to build programs for xtensa-$target-elf"
	install -Dm644 \
		"$builddir/xtensa_$target.so" \
		"$subpkgdir/usr/lib/xtensa-dynconfig/xtensa_$target.so"
}

sha512sums="
1f436a4561738b621b2e1e8306cacbac4984199a6e3c95f70d70df2791bdc025c2050b5e817274bfb5c2fbf4a6bd16fa9fd66fff6f85002fd50a0c44c277355f  xtensa-dynconfig-0_git20231013.tar.gz
1db13458c7604c8d5fa719aecf4a166c4f8b202e7fcabeadb250f038698fec50e8c6582e5b47136f81ff96039fc3d1811c5fe1f266bc69000e4e367fded62eec  xtensa-dynconfig-overlays-dd1cf19f6eb327a9db51043439974a6de13f5c7f.tar.gz
"
